#pragma once

#include "DecisionNode.h"

#include "Behavior.h"
#include "ObjectFlow.h"

namespace uml {

DecisionNode::DecisionNode(const QString& umlType)
    : ControlNode(umlType) {}

void DecisionNode::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    ControlNode::fromJson(json, errorList);
    decisionInput_ = JsonSerializable::create<Behavior>(json.value("decisionInput"), errorList);

    decisionInputFlow_ = JsonSerializable::create<ObjectFlow>(json.value("decisionInputFlow"), errorList);

}

void DecisionNode::toJson(QJsonObject& json) {
    ControlNode::toJson(json);
    if (decisionInput_) {
        QJsonObject decisionInput_json;
        decisionInput_->toJson(decisionInput_json);
        json.insert("decisionInput", decisionInput_json);
    }
    if (decisionInputFlow_) {
        QJsonObject decisionInputFlow_json;
        decisionInputFlow_->toJson(decisionInputFlow_json);
        json.insert("decisionInputFlow", decisionInputFlow_json);
    }
}

/// <summary>
/// decisionInput getter
/// A Behavior that is executed to provide an input to guard ValueSpecifications on
/// ActivityEdges outgoing from the DecisionNode.
/// </summary>
shared_ptr<Behavior> DecisionNode::decisionInput() const {
    return decisionInput_;
}

/// <summary>
/// decisionInput setter
/// A Behavior that is executed to provide an input to guard ValueSpecifications on
/// ActivityEdges outgoing from the DecisionNode.
/// </summary>
void DecisionNode::setDecisionInput(shared_ptr<Behavior> value) {
    decisionInput_ = value;
}

/// <summary>
/// decisionInputFlow getter
/// An additional ActivityEdge incoming to the DecisionNode that provides a decision
/// input value for the guards ValueSpecifications on ActivityEdges outgoing from
/// the DecisionNode.
/// </summary>
shared_ptr<ObjectFlow> DecisionNode::decisionInputFlow() const {
    return decisionInputFlow_;
}

/// <summary>
/// decisionInputFlow setter
/// An additional ActivityEdge incoming to the DecisionNode that provides a decision
/// input value for the guards ValueSpecifications on ActivityEdges outgoing from
/// the DecisionNode.
/// </summary>
void DecisionNode::setDecisionInputFlow(shared_ptr<ObjectFlow> value) {
    decisionInputFlow_ = value;
}

} // namespace uml
